import { getCensusBugMsg } from '@/services/statistics';

const model = {
  namespace: 'bugstatistics',
  state: {
    InsuranceTypeList: [{ name: '全部', value: '' }],
    AdviserUsers: [{ name: '全部', value: '' }],
    tableData: {
      list: [],
      pagination: {},
    },
  },
  effects: {
    *getCensusBugMsg({ payload }, { call, put }) {
      for (let i in payload) {
        if (!payload[i]) {
          delete payload[i];
        }
      }
      const { code, message, data } = yield call(getCensusBugMsg, payload);
      if (code === '000000') {
        const { censusBugList, pageNum, pageSize, total } = data;
        const pagination = { pageNum: pageNum, pageSize: pageSize, total: total }
        yield put({
          type: 'putList',
          payload: { list: censusBugList, pagination }
        });
      } else {
        console.log(message);
      }
    },
  },
  reducers: {
    putList(state, action) {
      const { payload } = action;
      payload.pagination.current = action.payload.pagination.pageNum;
      return { ...state, tableData: payload };
    },
  },
};
export default model;
